﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.WmsManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.WmsManagement.StoreTransferVMs
{
    public partial class StoreTransferListVM : BasePagedListVM<StoreTransfer_View, StoreTransferSearcher>
    {
        
        protected override IEnumerable<IGridColumn<StoreTransfer_View>> InitGridHeader()
        {
            return new List<GridColumn<StoreTransfer_View>>{
                
                this.MakeGridHeader(x => x.StoreTransfer_Sheet).SetTitle(@Localizer["Page.调拨单号"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_SheetCode).SetTitle(@Localizer["Page.调拨单号"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_Material).SetTitle(@Localizer["Page.调拨物料"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_MaterialName).SetTitle(@Localizer["Page.调拨物料"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_Qty).SetTitle(@Localizer["Page.调拨数量"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_TransferDate).SetTitle(@Localizer["Page.调拨时间"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.StoreTransfer_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<StoreTransfer_View> GetSearchQuery()
        {
            var query = DC.Set<StoreTransfer>()
                
                .CheckEqual(Searcher.SheetId, x=>x.SheetId)
                .CheckContain(Searcher.SheetCode, x=>x.SheetCode)
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .CheckContain(Searcher.MaterialName, x=>x.MaterialName)
                .CheckEqual(Searcher.Qty, x=>x.Qty)
                .CheckBetween(Searcher.TransferDate?.GetStartTime(), Searcher.TransferDate?.GetEndTime(), x => x.TransferDate, includeMax: false)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new StoreTransfer_View
                {
				    ID = x.ID,
                    
                    StoreTransfer_Sheet = x.Sheet.TenantCode,
                    StoreTransfer_SheetCode = x.SheetCode,
                    StoreTransfer_Material = x.Material.TenantCode,
                    StoreTransfer_MaterialName = x.MaterialName,
                    StoreTransfer_Qty = x.Qty,
                    StoreTransfer_TransferDate = x.TransferDate,
                    StoreTransfer_Status = x.Status,
                    StoreTransfer_CreateTime = x.CreateTime,
                    StoreTransfer_UpdateTime = x.UpdateTime,
                    StoreTransfer_CreateBy = x.CreateBy,
                    StoreTransfer_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class StoreTransfer_View: StoreTransfer
    {
        
        public string StoreTransfer_Sheet { get; set; }
        public string StoreTransfer_SheetCode { get; set; }
        public string StoreTransfer_Material { get; set; }
        public string StoreTransfer_MaterialName { get; set; }
        public decimal? StoreTransfer_Qty { get; set; }
        public DateTime? StoreTransfer_TransferDate { get; set; }
        public FormStatusEnum? StoreTransfer_Status { get; set; }
        public DateTime? StoreTransfer_CreateTime { get; set; }
        public DateTime? StoreTransfer_UpdateTime { get; set; }
        public string StoreTransfer_CreateBy { get; set; }
        public string StoreTransfer_UpdateBy { get; set; }

    }

}